var rdk = rdk || {};
rdk.manage = rdk.manage || {};
/**
 * 公众方法
 */
rdk.manage.comFn = {
	toManageTable : function(currentIndex) {
		var beginTime = $("#beginTime").val();
		var endTime = $("#endTime").val();

		var action = "workOrder/manageTable.do";
		var data = {
			currentIndex : currentIndex,
			beginTime : beginTime,
			endTime : endTime,
			type : $("#workOrderType").val(),
			status : $("#workOrderStatus").val(),
			id:$("#id").val(),
			imei:$("#imei").val()

		};
		base.AJAX_POST(action, data, 'html', function(html) {
			$("#manage_table").empty().append($(html));
		});

	}
},

// 订单列表JS
rdk.manage.manageList = {
	init : function() {
		this.page.init();
		this.btn.init();
	},
	btn : {
		init : function() {
			this.search();
			this.exportExcel();
		},
		exportExcel : function() {
			$("#export").click(
					function() {
						var action = '../workOrder/toExcel.do?beginTime='
								+ $("#beginTime").val() + '&endTime='
								+ $("#endTime").val() + "&currentInd="
								+ parseInt($("#currentIndex").val()) + "&type="
								+ $("#workOrderType").val() + "&status="
								+ $("#workOrderStatus").val()+"&id="+$("#id").val();
						location.href = action;
					});
		},
		search : function() {
			$("#search").click(function() {
				var beginTime = $("#beginTime").val();
				var endTime = $("#endTime").val();
				var action = "workOrder/manageTable.do";
				var data = {
					currentIndex : parseInt($("#currentIndex").val()),
					beginTime : beginTime,
					endTime : endTime,
					type : $("#workOrderType").val(),
					status : $("#workOrderStatus").val(),
					id:$("#id").val(),
					imei:$("#imei").val()
					
				};
				base.AJAX_POST(action, data, 'html', function(html) {
					$("#manage_table").empty().append($(html));
				});
			});
		}

	},

	page : {
		init : function() {
			this.loadUserTable();
		},

		loadUserTable : function() {
			rdk.manage.comFn.toManageTable(1);
		}
	}

},

rdk.manage.manageTable = {
	init : function() {
		this.page.init();
	},
	page : {
		init : function() {
			this.opreation.pagenation();
		},
		opreation : {
			init : function() {
			},
			detail:function(id){
				var action="workOrder/comment.do?id="+id;
				base.getAction(action);
			},
			updateRoleStatus : function(orderId, status) {
				bootbox.dialog({
					message : "确定对该工单进行该操作？",
					title : "提示信息",
					buttons : {
						OK : {
							label : "确定",
							className : "btn-primary",
							callback : function() {
								$.ajax({
									url : '../workOrder/updateStatus.do',
									data : {
										orderId : orderId,
										status : status
									},
									success : function(data) {
										if ("error" == data) {
											bootbox.alert('此工单不可进行该操作');
										} else if ("false" == data) {
											bootbox.alert("操作失败");
											rdk.manage.comFn.toManageTable(1);

										} else if ("true" == data) {
											bootbox.alert("操作成功");
											rdk.manage.comFn.toManageTable(1);
										}
									}
								});
							}
						},

						Cancel : {
							label : "取消",
							className : "btn-default",
							callback : function() {

							}
						}
					}
				});
			},
			pagenation : function() {
				$(".tcdPageCode").createPage({
					pageCount : parseInt($("#totalPage").val()),
					current : parseInt($("#currentIndex").val()),
					backFn : function(p) {
						rdk.manage.comFn.toManageTable(p);
					}
				});
			}
		}
	}
};
